//
//  YYMainViewController.swift
//  WeiBo001
//
//  Created by geduo on 2018/5/9.
//  Copyright © 2018年 geduo. All rights reserved.
//

import UIKit

class YYMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
//        self.tabBar = YYTabbar()
        let tabbar = YYTabbar()
        tabbar.composeButtonClosure = {[weak self] in
            
            print(self as Any)
        }
        
        tabbar.hmDelegate = self as! YYTabBarDelegate
        
        setValue(tabbar, forKey: "tabBar")
        UITabBar.appearance().tintColor = UIColor.orange
        
        addChildViewController(childController: YYHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(childController: YYMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: YYDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: YYProfileViewController(), title: "我的", imageName: "tabbar_profile")
        
    }
//添加自视图控制器的重载方法
    func addChildViewController(childController: UIViewController,title:String, imageName:String) {
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        childController.tabBarItem.setTitleTextAttributes([NSAttributedStringKey.font:UIFont.systemFont(ofSize: 14)], for: .normal)
        childController.tabBarItem.setTitleTextAttributes([NSAttributedStringKey.foregroundColor:UIColor.orange], for: .selected)
        
        childController.tabBarItem.title = title
        childController.navigationItem.title = title
        
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
    }

}

//使用extension可以实现代理方法
extension YYMainViewController: YYTabBarDelegate{
    func didSelectedComposeButton() {
        print("我是通过代理过来的")
    }
}
